package com.jixi;

import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

import java.io.IOException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;

public class Coze_Chat_Message_TEST {
	public static void main(String[] args) {
		/*
		final OkHttpClient HTTP_CLIENT = new OkHttpClient().newBuilder().build();
		
		// 准备URL和查询参数
		String conversationId = "7480841487232794675";
		String chatId = "7480841487232811059";
		
		// 对查询参数进行URL编码
		try {
			conversationId = URLEncoder.encode(conversationId, StandardCharsets.UTF_8);
			chatId = URLEncoder.encode(chatId, StandardCharsets.UTF_8);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		// 构建带有查询参数的URL
		String url = String.format("https://api.coze.cn/v3/chat/message/list?conversation_id=%s&chat_id=%s", conversationId, chatId);
		
		Request request = new Request.Builder()
				.url(url)
				.get()
				.addHeader("Content-Type", "application/json")
				.addHeader("Authorization", "Bearer " + "czs_lf9o9jVqBkBUbkVXHbOXZoErA5WVdaYjPlLDz3D5Uh0lRMfLDFJKISftNcDHtDzPT")
				.build();
		
		try (Response response = HTTP_CLIENT.newCall(request).execute()) {
			if (response.isSuccessful()) {
				if (response.body() != null) {
					String str = response.body().string();
					System.out.println(str);
				}
			} else {
				// 输出错误信息
				if (response.body() != null) {
					System.err.println("请求失败: " + response.code() + " " + response.message());
					System.err.println(response.body().string());
				} else {
					System.err.println("请求失败: " + response.code() + " " + response.message());
				}
			}
		} catch (IOException e) {
			// 捕获网络请求过程中可能发生的IO异常
			System.err.println("请求异常: ");
			e.printStackTrace();
		}
		*/
	}

}
